import { injectable, InjectableObject } from "../inject";
import { ICommandMap } from "./base/ICommandMap";
import { IMediatorMap } from "./base/IMediatorMap";
import { IViewMap } from "./base/IViewMap";
import { CommandMap } from "./impl/CommandMap";
import { MediatorMap } from "./impl/MediatorMap";
import { ViewMap } from "./impl/ViewMap";

@injectable('Context')
export class Context extends InjectableObject {
    protected _commandMap: ICommandMap = null;

    protected _mediatorMap: IMediatorMap = null;

    protected _viewMap: IViewMap = null;

    constructor() {
        super();

        this.mapInjections();
    }

    mapInjections() {
        this.injector.mapValue('core.CommandMap', this.commandMap);
        this.injector.mapValue('core.MediatorMap', this.mediatorMap);
        this.injector.mapValue('core.ViewMap', this.viewMap);
    }

    unmapInjections() {
        this.injector.unmap('core.CommandMap');
        this.injector.unmap('core.MediatorMap');
        this.injector.unmap('core.ViewMap');
    }

    public get commandMap(): ICommandMap {
        if (!this._commandMap) {
            this._commandMap = new CommandMap();
        }

        return this._commandMap;
    }

    public get mediatorMap(): IMediatorMap {
        if (!this._mediatorMap) {
            this._mediatorMap = new MediatorMap();
        }

        return this._mediatorMap;
    }

    public get viewMap(): IViewMap {
        if (!this._viewMap) {
            this._viewMap = new ViewMap();
        }

        return this._viewMap;
    }

    startup(): void {

    }

    shutdown(): void {

    }
}